# -*- coding: utf-8 -*-
import json
from decimal import *

nos = []
with open('C:/Users/皮大熊.HL/Desktop/log/bl.txt', 'r', encoding='utf-8') as fi:
    for line in fi:
        nos.append(line.replace('\n', ''))
print('单号数：' + str(len(nos)))

logs = []
with open('C:/Users/皮大熊.HL/Desktop/log/log.txt', 'r', encoding='utf-8') as file:
    lines = file.readlines()
    for line in lines:
        logs.append(line.replace('\n', ''))
print('日志数：' + str(len(logs)))

contents = []
ns = []
for no in nos:
    for log in logs:
        if log.find(no) != -1:
            contents.append(log)
            ns.append(no)
            break
print('过滤后日志数：' + str(len(contents)))
print('过滤后单号数：' + str(len(ns)))

sub = frozenset(ns)
mst = frozenset(nos)
print(mst - sub)

# 打开文件进行写入
# with open('C:/Users/皮大熊.HL/Desktop/log/output.log', 'a') as file:
#     for content in contents:
#         file.write(content + '\n')

with open('C:/Users/皮大熊.HL/Desktop/log/final_output.log', 'a', encoding='utf-8') as file:
    num = Decimal('0.000')
    nums = []
    for content in contents:
        var = content.split(': 出库推送电商实提参数：')[1]
        # file.write(var + '\n')
        json_obj = json.loads(var)
        # print(json_obj['actualDetail'])
        pickDetails = json_obj['pickDetails']
        for item in pickDetails:
            if item['productCode'] == '10015040':
                d = Decimal(item['tonActual'])
                nums.append(d)
                num += d
    print(len(nums))
    print(num)
